<html>
  <head>
    <title></title>
    <style></style>
    <script type="text/tiscript">
    
    var serverSocket = null;
    
    // simple echo server
    function serve() {
    
      var log = $(pre#out);
    
      function acceptConnection(socket) 
      {
        log.text = "got connection";
        socket << event data( data ) // subscribe on "data" event
        {
          log.text += JSON.stringify(data,"  ");
          socket.send(data);
        };
        return true; // we accept this connection
      }
    
      serverSocket = DataSocket.listen(acceptConnection,22349);
      log.text = "Listening on port 22349";
      
      $(button#serve).remove();
    
    }
    
    event click $(button#serve) { 
       serve(); 
    }
    
    
    </script>
  </head>
<body>

  <button #serve>Start server</button>
  <pre #out>
  </pre>

</body>
</html>
